﻿#include "DialogDataImportConfiguration.h"
#include "ui_DialogDataImportConfiguration.h"

#include <QTabWidget>
#include <QTabBar>
#include <QIntValidator>
#include "DataImportConfigurationData.h"
#include "BaseModule/IBaseSignal.h"
#include "BaseWidget/IdaWidgetHelper.h"
#include "BaseWidget/IdaDialogMsg.h"
#include "BaseModule/GlobalHelper.h"
#include "MainWindowSignalHandler.h"
#include <QFile>
#include <QDebug>

namespace pst
{
    int GetResultParaType(const QString& category)
    {
        int resultParaType = -1;
        if (category.contains("电场-近场"))
        {
            resultParaType = 0;
        }
        else if (category.contains("电场-远场"))
        {
            resultParaType = 1;
        }
        else if (category.contains("磁场-近场"))
        {
            resultParaType = 20;
        }
        else if (category.contains("电流"))
        {
            resultParaType = 11;
        }
        else if (category.contains("电压"))
        {
            resultParaType = 10;
        }
        else if (category.contains("功率"))
        {
            resultParaType = 16;
        }
        else if (category.contains("人体吸收比"))
        {
            resultParaType = 13;
        }
        else if (category.contains("增益"))
        {
            resultParaType = 7;
        }
        else if (category.contains("方向性系数"))
        {
            resultParaType = 19;
        }
        else if (category.contains("方向性系数"))
        {
            resultParaType = 19;
        }
        else if (category.contains("雷达散射截面"))
        {
            resultParaType = 18;
        }
        else if (category.contains("S参数"))
        {
            resultParaType = 8;
        }
        else if (category.contains("驻波比"))
        {
            resultParaType = 9;
        }
        return resultParaType;
    }

    DialogDataImportConfiguration::DialogDataImportConfiguration(const QString& fileName, QWidget* parent)
        : IdaDialogFrame(parent), ui(new Ui::DialogDataImportConfiguration()), m_DataRowMax(20)
    {
        ui->setupUi(this);
        m_filePath = fileName;
        ReadText(fileName);
        initWidget();
        initConnects();
        // connect(ui->tabWidget, SIGNAL(currentChanged(int)), this, SLOT(updateSizes(int)));
        GetStartLine();
        on_radioButton_Tab_clicked();
        ProhibitAttributeSettings();
    }

    DialogDataImportConfiguration::~DialogDataImportConfiguration()
    {
        delete ui;
    }

    void DialogDataImportConfiguration::initWidget()
    {
        // 整体
        // setWindowSize(740, 400);
        setWindowTitle(QStringLiteral("数据导入配置"));
        ui->tabWidget->tabBar()->hide();
        ui->tabWidget->setStyleSheet("QTabWidget::pane { border: 0px; }");
        ui->tableWidget_DataPreviewSelection->setStyleSheet("QTableWidget { border: none; }");

        // page1
        ui->lineEdit_Other->setEnabled(false);
        // ui->tabWidget->setTabEnabled(1, false);
        // m_DataRowMax = 20;//根据实际行数设置范围
        ui->spinBox_DataStartRow->setRange(1, m_DataRowMax); // 设置数据起始行数据范围
        ui->spinBox_ReadLines->setEnabled(false);

        // page2
        QIntValidator* intValidator = new QIntValidator(1, m_DataRowMax, this);
        ui->lineEdit_Relevance->setValidator(intValidator);
        ui->lineEdit_Relevance->setEnabled(false);
        ui->label_NoStats->setEnabled(true);
        ui->radioButton_NoStats->setChecked(true);
        ui->radioButton_VariableSetting->setChecked(false);
        ui->groupBox_Variable->setEnabled(false);
        ui->groupBox_DependentVariable->setEnabled(false);
        ui->checkBox_Relevance->setEnabled(false);

        // page 3
        QDoubleValidator* doubleValidator = new QDoubleValidator(-999999999999999, 999999999999999, 5, this);
        doubleValidator->setNotation(QDoubleValidator::StandardNotation);
        QIntValidator* intValidatorSamplingNumber = new QIntValidator(1, 999999999999999, this);

        ui->lineEdit_XBegin->setValidator(doubleValidator);
        ui->lineEdit_XEnd->setValidator(doubleValidator);
        ui->lineEdit_XSamplingNumber->setValidator(intValidatorSamplingNumber);

        ui->lineEdit_YBegin->setValidator(doubleValidator);
        ui->lineEdit_YEnd->setValidator(doubleValidator);
        ui->lineEdit_YSamplingNumber->setValidator(intValidatorSamplingNumber);

        ui->lineEdit_ZBegin->setValidator(doubleValidator);
        ui->lineEdit_ZEnd->setValidator(doubleValidator);
        ui->lineEdit_ZSamplingNumber->setValidator(intValidatorSamplingNumber);

        ui->lineEdit_ThetaBegin->setValidator(doubleValidator);
        ui->lineEdit_ThetaEnd->setValidator(doubleValidator);
        ui->lineEdit_ThetaSamplingNumber->setValidator(intValidatorSamplingNumber);

        ui->lineEdit_PhiBegin->setValidator(doubleValidator);
        ui->lineEdit_PhiEnd->setValidator(doubleValidator);
        ui->lineEdit_PhiSamplingNumber->setValidator(intValidatorSamplingNumber);

        // 初始化变量类别数据
        m_VariableCategoryData = DataImportConfigurationDataInstance->getVariableCategoryData();
        m_VariableCategoryTotalData = DataImportConfigurationDataInstance->getVariableCategoryTotalData();
        ui->comboBox_VariableCategory->addItems(m_VariableCategoryData);

        // 初始化因变量数据
        m_DependentVariableData = DataImportConfigurationDataInstance->getDependentVariableData();
        m_DependentVariableCategoryData1 = DataImportConfigurationDataInstance->getDependentVariableCategoryData1();
        m_DependentVariableCategoryData2 = DataImportConfigurationDataInstance->getDependentVariableCategoryData2();
        m_DependentVariableCategoryUnitData = DataImportConfigurationDataInstance->getDependentVariableCategoryUnitData();
        ui->comboBox_DependentVariable->addItems(m_DependentVariableData);

        // 底部
        ui->pushButton_LastStep->hide();
        ui->pushButton_Finish->hide();
        IdaWidgetHelperInstance->setMainButtonStyle(ui->pushButton_Finish);
        IdaWidgetHelperInstance->setMainButtonStyle(ui->pushButton_NextStep);

        ui->tabWidget->setCurrentIndex(0);
        m_widget_page0 = ui->tabWidget->widget(0);
        m_widget_page1 = ui->tabWidget->widget(1);
        m_widget_page2 = ui->tabWidget->widget(2);
        ui->tabWidget->removeTab(1);
        ui->tabWidget->removeTab(1);
    }

    void DialogDataImportConfiguration::ReadText(const QString& fileName)
    {
        QFile file(fileName);
        if (!file.open(QIODevice::ReadOnly))
        {
            qDebug() << fileName << " open error!!!";
            return;
        }
        while (!file.atEnd())
        {
            QString text = file.readLine();
            text = text.trimmed();
            if (!text.isEmpty())
            {
                m_text.append(text);
            }
        }
        m_DataRowMax = m_text.size();
        file.close();
    }

    void DialogDataImportConfiguration::updateSizes(int index)
    {
        for (int i = 0; i < ui->tabWidget->count(); i++)
        {
            if (i != index)
            {
                ui->tabWidget->widget(i)->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
            }
        }

        ui->tabWidget->widget(index)->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
        ui->tabWidget->widget(index)->resize(ui->tabWidget->widget(index)->minimumSizeHint());
        ui->tabWidget->widget(index)->adjustSize();
    }

    void DialogDataImportConfiguration::on_radioButton_Tab_clicked()
    {
        auto _isChecked = ui->radioButton_Tab->isChecked();
        if (_isChecked)
        {
            ui->lineEdit_Other->setEnabled(false);
            m_splitReg = QRegularExpression("\t+");
            ParserData();
        }
    }

    void DialogDataImportConfiguration::on_radioButton_Space_clicked()
    {
        auto _isChecked = ui->radioButton_Space->isChecked();
        if (_isChecked)
        {
            ui->lineEdit_Other->setEnabled(false);
            m_splitReg = QRegularExpression(" +");
            ParserData();
        }
    }

    void DialogDataImportConfiguration::on_radioButton_Comma_clicked()
    {
        auto _isChecked = ui->radioButton_Comma->isChecked();
        if (_isChecked)
        {
            ui->lineEdit_Other->setEnabled(false);
            m_splitReg = QRegularExpression(",");
            ParserData();
        }
    }

    void DialogDataImportConfiguration::on_radioButton_Other_clicked()
    {
        auto _isChecked = ui->radioButton_Other->isChecked();
        if (_isChecked)
        {
            ui->lineEdit_Other->setEnabled(true);
        }
    }

    void DialogDataImportConfiguration::on_spinBox_DataStartRow_valueChanged(int arg1)
    {
        ui->spinBox_DataStartRow->setEnabled(false);
        auto _value = ui->spinBox_DataStartRow->value();
        // 读取行数数据跟随起始行变化
        ui->spinBox_ReadLines->setRange(1, m_DataRowMax - arg1 + 1); // 设置读取行数数据范围
        ui->spinBox_DataStartRow->setEnabled(true);
        ParserData();
        ui->spinBox_DataStartRow->setFocus();
    }

    void DialogDataImportConfiguration::on_spinBox_ReadLines_valueChanged(int arg1)
    {
        auto _value = ui->spinBox_ReadLines->value();
        ParserData();
    }

    void DialogDataImportConfiguration::on_checkBox_ReadLines_stateChanged(int arg1)
    {
        auto _isChecked = ui->checkBox_ReadLines->isChecked();
        if (_isChecked)
        {
            ui->spinBox_ReadLines->setEnabled(true);
        }
        else
        {
            ui->spinBox_ReadLines->setEnabled(false);
        }
        ParserData();
    }

    void DialogDataImportConfiguration::on_checkBox_IncludeTitle_stateChanged(int arg1)
    {
        auto _checkState = ui->checkBox_IncludeTitle->checkState();
        ParserData();
    }

    void DialogDataImportConfiguration::on_radioButton_NoStats_clicked()
    {
        ui->label_NoStats->setEnabled(true);
        ui->groupBox_Variable->setEnabled(false);
        ui->groupBox_DependentVariable->setEnabled(false);
        RestoreDefaultKeyShow();
        RestoreDefaultValueShow();
        for (int index : m_selectColumnSet)
        {
            auto& dataProperty = m_dataProperty[index];
            RestoreNoneProperty(dataProperty);
        }
    }

    void DialogDataImportConfiguration::on_radioButton_VariableSetting_clicked()
    {
        ui->label_NoStats->setEnabled(false);
        ui->groupBox_Variable->setEnabled(true);
        ui->groupBox_DependentVariable->setEnabled(false);
        if (m_selectColumnSet.size() == 1)
        {
            auto& dataProperty = m_dataProperty[*m_selectColumnSet.begin()];
            SetKeyProperty(dataProperty);
        }
    }

    void DialogDataImportConfiguration::on_radioButton_DependentVariableSetting_clicked()
    {
        ui->label_NoStats->setEnabled(false);
        ui->groupBox_Variable->setEnabled(false);
        if (m_selectColumnSet.size() == 1)
        {
            auto& property = m_dataProperty[*m_selectColumnSet.begin()];
            if (property.type == Value && !property.isAssociation && property.associationColumn != -1)
            {
                ui->groupBox_DependentVariable->setEnabled(false);
                return;
            }
        }
        ui->groupBox_DependentVariable->setEnabled(true);
        for (int index : m_selectColumnSet)
        {
            auto& dataProperty = m_dataProperty[index];
            SetValueProperty(dataProperty,false);
        }
    }

    void DialogDataImportConfiguration::on_lineEdit_VariableName_returnPressed()
    {
        auto _text = ui->lineEdit_VariableName->text();
        if (m_selectColumnSet.size() == 1)
        {
            auto& dataProperty = m_dataProperty[*m_selectColumnSet.begin()];
            dataProperty.name = ui->lineEdit_VariableName->text();
            UpdateDataShow();
        }
    }

    void DialogDataImportConfiguration::on_comboBox_VariableCategory_currentIndexChanged(int index)
    {
        auto _tempPair = m_VariableCategoryTotalData.at(index);
        auto _currentText = ui->comboBox_VariableCategory->currentText();
        if (_tempPair.first == _currentText)
        {
            ui->comboBox_VariableCategoryUnit->clear();
            ui->comboBox_VariableCategoryUnit->addItems(_tempPair.second);
        }
        if (m_selectColumnSet.size() == 1)
        {
            auto& dataProperty = m_dataProperty[*m_selectColumnSet.begin()];
            dataProperty.category = ui->comboBox_VariableCategory->currentText();
            dataProperty.unit = ui->comboBox_VariableCategoryUnit->currentText();
            // UpdateDataShow();
        }
    }

    void DialogDataImportConfiguration::on_comboBox_VariableCategoryUnit_currentIndexChanged(int index)
    {
        if (m_selectColumnSet.size() == 1)
        {
            auto& dataProperty = m_dataProperty[*m_selectColumnSet.begin()];
            dataProperty.unit = ui->comboBox_VariableCategoryUnit->currentText();
            // UpdateDataShow();
        }
    }

    void DialogDataImportConfiguration::on_lineEdit_DependentVariableName_returnPressed()
    {
        for (int index : m_selectColumnSet)
        {
            auto& dataProperty = m_dataProperty[index];
            SetValueProperty(dataProperty);
        }
    }

    void DialogDataImportConfiguration::on_comboBox_DependentVariable_currentIndexChanged(int index)
    {
        auto _tempDependentVariable = m_DependentVariableData.at(index);
        auto _currentText = ui->comboBox_DependentVariable->currentText();

        //设置为 因变量（实部+虚部）则“该列数值是否为对数（dB）状态”项处于不勾选且禁用状态
        if (_currentText ==  "因变量（实部+虚部）")
        {
            ui->checkBox_dB->setChecked(false);
            ui->checkBox_dB->setDisabled(true);
        }
        else
        {
            ui->checkBox_dB->setEnabled(true);

        }

        if (_tempDependentVariable == _currentText)
        {
            ui->comboBox_DependentVariableCategory->clear();
            if (_tempDependentVariable == QString("因变量（标量）"))
            {
                ui->label_DependentVariable1->clear();
                ui->comboBox_DependentVariableCategory->addItems(m_DependentVariableCategoryData1);
                ui->checkBox_Relevance->setEnabled(false);
                ui->checkBox_Relevance->setChecked(false);
            }
            else
            {
                ui->label_DependentVariable1->setText(_tempDependentVariable.mid(4, 2));
                ui->comboBox_DependentVariableCategory->addItems(m_DependentVariableCategoryData2);
                ui->checkBox_Relevance->setEnabled(false);
                ui->checkBox_Relevance->setChecked(true);
            }
        }
        for (int index : m_selectColumnSet)
        {
            auto& dataProperty = m_dataProperty[index];
            SetValueProperty(dataProperty);
        }
    }

    void DialogDataImportConfiguration::on_comboBox_DependentVariableCategory_currentIndexChanged(int index)
    {
        auto _currentText = ui->comboBox_DependentVariableCategory->currentText();
        for (auto _tempPair : m_DependentVariableCategoryUnitData)
        {
            if (_tempPair.first == _currentText)
            {
                ui->comboBox_DependentVariableCategoryUnit->clear();
                ui->comboBox_DependentVariableCategoryUnit->addItems(_tempPair.second);
                break;
            }
        }
        for (int index : m_selectColumnSet)
        {
            auto& dataProperty = m_dataProperty[index];
            SetValueProperty(dataProperty);
        }
    }
    void DialogDataImportConfiguration::on_comboBox_DependentVariableCategoryUnit_currentIndexChanged(int index)
    {
        for (int index : m_selectColumnSet)
        {
            auto& dataProperty = m_dataProperty[index];
            SetValueProperty(dataProperty);
        }
    }

    void DialogDataImportConfiguration::on_checkBox_Relevance_stateChanged(int arg1)
    {
        auto _ischecked = ui->checkBox_Relevance->isChecked();
        if (_ischecked)
        {
            ui->lineEdit_Relevance->setEnabled(true);
        }
        else
        {
            ui->lineEdit_Relevance->setEnabled(false);
        }
        for (int index : m_selectColumnSet)
        {
            auto& dataProperty = m_dataProperty[index];
            SetValueProperty(dataProperty);
        }
    }
    void DialogDataImportConfiguration::on_lineEdit_Relevance_returnPressed()
    {
        auto _text = ui->lineEdit_Relevance->text();
        if (_text.toInt() < m_selectColumnSet.size())
        {
            IBaseSignalInstance->signal_sendErrorMessageToUI("关联列数小于选中列数！！！");
            return;
        }
        for (int index : m_selectColumnSet)
        {
            auto& dataProperty = m_dataProperty[index];
            SetValueProperty(dataProperty);
        }
    }
    void DialogDataImportConfiguration::on_checkBox_dB_stateChanged(int arg1)
    {
        auto _ischecked = ui->checkBox_dB->isChecked();
        for (int index : m_selectColumnSet)
        {
            auto& dataProperty = m_dataProperty[index];
            SetValueProperty(dataProperty);
        }
    }

    // page3
    void DialogDataImportConfiguration::on_checkBox_2DGraph_stateChanged(int arg1)
    {
        auto _ischecked = ui->checkBox_2DGraph->isChecked();
    }
    void DialogDataImportConfiguration::on_checkBox_PolarGraph_stateChanged(int arg1)
    {
        auto _ischecked = ui->checkBox_PolarGraph->isChecked();
    }
    void DialogDataImportConfiguration::on_checkBox_TwoDHeatMap_stateChanged(int arg1)
    {
        auto _ischecked = ui->checkBox_TwoDHeatMap->isChecked();
    }
    void DialogDataImportConfiguration::on_checkBox_3DSurfacePlot_stateChanged(int arg1)
    {
        auto _ischecked = ui->checkBox_3DSurfacePlot->isChecked();
        // 三维曲面图参数设置随复选框的勾选启用，去勾选禁用
        ui->label_ThetaBegin->setEnabled(_ischecked);
        ui->lineEdit_ThetaBegin->setEnabled(_ischecked);
        ui->label_ThetaEnd->setEnabled(_ischecked);
        ui->lineEdit_ThetaEnd->setEnabled(_ischecked);
        ui->label_ThetaSamplingNumber->setEnabled(_ischecked);
        ui->lineEdit_ThetaSamplingNumber->setEnabled(_ischecked);
        ui->label_PhiBegin->setEnabled(_ischecked);
        ui->lineEdit_PhiBegin->setEnabled(_ischecked);
        ui->label_PhiEnd->setEnabled(_ischecked);
        ui->lineEdit_PhiEnd->setEnabled(_ischecked);
        ui->label_PhiSamplingNumber->setEnabled(_ischecked);
        ui->lineEdit_PhiSamplingNumber->setEnabled(_ischecked);
    }
    void DialogDataImportConfiguration::on_checkBox_3DCloudMap_stateChanged(int arg1)
    {
        auto _ischecked = ui->checkBox_3DCloudMap->isChecked();
        // 三维云图参数设置随复选框的勾选启用，去勾选禁用
        ui->label_XBegin->setEnabled(_ischecked);
        ui->lineEdit_XBegin->setEnabled(_ischecked);
        ui->label_XEnd->setEnabled(_ischecked);
        ui->lineEdit_XEnd->setEnabled(_ischecked);
        ui->label_XSamplingNumber->setEnabled(_ischecked);
        ui->lineEdit_XSamplingNumber->setEnabled(_ischecked);
        ui->label_YBegin->setEnabled(_ischecked);
        ui->lineEdit_YBegin->setEnabled(_ischecked);
        ui->label_YEnd->setEnabled(_ischecked);
        ui->lineEdit_YEnd->setEnabled(_ischecked);
        ui->label_YSamplingNumber->setEnabled(_ischecked);
        ui->lineEdit_YSamplingNumber->setEnabled(_ischecked);
        ui->label_ZBegin->setEnabled(_ischecked);
        ui->lineEdit_ZBegin->setEnabled(_ischecked);
        ui->label_ZEnd->setEnabled(_ischecked);
        ui->lineEdit_ZEnd->setEnabled(_ischecked);
        ui->label_ZSamplingNumber->setEnabled(_ischecked);
        ui->lineEdit_ZSamplingNumber->setEnabled(_ischecked);
    }
    void DialogDataImportConfiguration::on_checkBox_Table_stateChanged(int arg1)
    {
        auto _ischecked = ui->checkBox_Table->isChecked();
    }

    void DialogDataImportConfiguration::on_pushButton_NextStep_clicked()
    {
        auto _currentWidget = ui->tabWidget->currentWidget();
        if (_currentWidget == m_widget_page0)
        {
            for (int i = 0; i < m_data.size(); ++i)
            {
                const auto& cloumnData = m_data[i];
                for (int j = 0; j < cloumnData.size(); ++j)
                {
                    if (!cloumnData.at(j).first)
                    {
                        IBaseSignalInstance->signal_sendErrorMessageToUI("数据错误");
                        return;
                    }
                }
            }
            ui->tabWidget->removeTab(0);
            ui->tabWidget->addTab(m_widget_page1, QStringLiteral(""));
            ui->pushButton_LastStep->show();
            ui->pushButton_NextStep->show();
            // setWindowSize(382, 609);
        }
        else
        {
            bool isPolarGraph = false, isTwoDHeatMap = false, is3DSurfacePlot = false, is3DCloudMap = false;
            int keyNumber = 0, valueNumber = 0;
            QStringList nameList;
            QStringList categoryList;
            int differentValueNum = 0;
            for (int i = 0; i < m_dataProperty.size(); ++i)
            {
                const auto& property = m_dataProperty.at(i);
                QString name;
                if (property.type == Key)
                {
                    ++keyNumber;
                    name = property.name;
                    if (!categoryList.contains(property.category))
                        categoryList.append(property.category);
                    else
                    {
                        IBaseSignalInstance->signal_sendErrorMessageToUI(QStringLiteral("变量列的参数类型设置必须是唯一的，请检查变量列的属性设置！"));
                        return;
                    }
                    QVector<double> cloumn;
                    cloumn.reserve(m_data.size());
                    for (const auto& cloumnData : m_data)
                    {
                        cloumn.append(cloumnData.at(i).second.toDouble());
                    }
                    const auto& minMax = std::minmax_element(cloumn.begin(), cloumn.end());
                    if (std::abs(*minMax.second - *minMax.first) > std::numeric_limits<double>::epsilon())
                    {
                        differentValueNum++;
                    }
                }
                else if (property.type == Value)
                {
                    ++valueNumber;
                    name = property.name + "_" + property.dependentVariableType;
                }
                else if (property.type == None)
                {
                    continue;
                }
                if (nameList.contains(name) || property.name.isEmpty())
                {
                    IBaseSignalInstance->signal_sendErrorMessageToUI("数据列标题名称存在空值或重复情形，请检查数据列名称设置。");
                    return;
                }
                else
                {
                    nameList.append(name);
                }
            }
            if (keyNumber == 0 || valueNumber == 0)
            {
                IBaseSignalInstance->signal_sendErrorMessageToUI("数据中需包含至少一列变量和一列因变量，请检查列属性设置。");
                return;
            }
            ui->tabWidget->removeTab(0);
            ui->tabWidget->addTab(m_widget_page2, QStringLiteral(""));

            ui->pushButton_LastStep->show();
            ui->pushButton_NextStep->hide();
            ui->pushButton_Finish->show();
            // ui->groupBox_3->hide();
            // setWindowSize(382, 500);

            isPolarGraph = categoryList.contains("Theta") || categoryList.contains("Phi");
            isTwoDHeatMap = keyNumber > 1 && differentValueNum > 1;
            is3DSurfacePlot = categoryList.contains("Theta") && categoryList.contains("Phi");
            is3DCloudMap = categoryList.contains("X坐标") && categoryList.contains("Y坐标") && categoryList.contains("Z坐标");
            ui->checkBox_PolarGraph->setEnabled(isPolarGraph);
            if (!isPolarGraph)
            {
                ui->checkBox_PolarGraph->setChecked(false);
            }
            ui->checkBox_TwoDHeatMap->setEnabled(isTwoDHeatMap);
            if (!isTwoDHeatMap)
            {
                ui->checkBox_TwoDHeatMap->setChecked(false);
            }
            ui->checkBox_3DSurfacePlot->setEnabled(is3DSurfacePlot);
            if (!is3DSurfacePlot)
            {
                ui->checkBox_3DSurfacePlot->setChecked(false);
            }
            ui->checkBox_3DCloudMap->setEnabled(is3DCloudMap);
            if (!is3DCloudMap)
            {
                ui->checkBox_3DCloudMap->setChecked(false);
            }
        }

        //// 根据数据是否包干列标题勾选框是否勾选设置变量名列标题
        // auto _ischeked = ui->checkBox_IncludeTitle->isChecked();
        // if (_ischeked)
        //{
        //     ui->lineEdit_VariableName->setText(QStringLiteral("列标题默认值"));
        //     ui->lineEdit_DependentVariableName->setText(QStringLiteral("列标题默认值"));
        // }
        // else
        //{
        //     ui->lineEdit_VariableName->setText(QStringLiteral("无列标题默认值"));
        //     ui->lineEdit_DependentVariableName->setText(QStringLiteral("无列标题默认值"));
        // }
        slot_TableSelectChange();
    }
    void DialogDataImportConfiguration::on_pushButton_LastStep_clicked()
    {
        auto _currentWidget = ui->tabWidget->currentWidget();
        if (_currentWidget == m_widget_page2)
        {
            ui->tabWidget->removeTab(0);
            ui->tabWidget->addTab(m_widget_page1, QStringLiteral(""));
            ui->pushButton_LastStep->show();
            ui->pushButton_NextStep->show();
            ui->pushButton_Finish->hide();
            ui->groupBox_3->show();
            // setWindowSize(382, 609);
        }
        else
        {
            ui->tabWidget->removeTab(0);
            ui->tabWidget->addTab(m_widget_page0, QStringLiteral(""));
            ui->pushButton_LastStep->hide();
            ui->pushButton_Finish->hide();
            ui->pushButton_NextStep->show();
            // setWindowSize(284, 517);
        }
        // updateSizes(0);
        // this->adjustSize();
        // this->resize(this->minimumSizeHint());
    }
    void DialogDataImportConfiguration::on_pushButton_Finish_clicked()
    {

        IBaseSignalInstance->signal_UpdateStatusBarInformation(QString("导入数据正在进行中..."), true);
        QCoreApplication::processEvents();
        QVector<std::tuple<QString, DataProperty, QVector<double>>> datas;
        // datas.resize(m_dataProperty.size());
        for (int i = 0; i < m_dataProperty.size(); ++i)
        {
            const auto& dataProperty = m_dataProperty.at(i);
            if (dataProperty.type == None)
            {
                continue;
            }
            QVector<double> vectorTmp;
            int coefficient = 20;
            switch (GetResultParaType(dataProperty.category))
            {
            case 7:
            case 13:
            case 16:
            case 17:
            case 18:
                coefficient = 10;
                break;
            default:
                break;
            }
            for (int j = 0; j < m_data.size(); ++j)
            {
                const auto& dataVector = m_data.at(j);
                double n = dataVector.at(i).second.toDouble();
                if (dataProperty.type == Value && dataProperty.isDB)
                {
                    n /= coefficient;
                    n = std::pow(10, n);
                }
                vectorTmp.append(n);
            }
            QString name = dataProperty.name;
            if (dataProperty.type == Value && !dataProperty.dependentVariableType.isEmpty())
            {
                if (dataProperty.dependentVariableType == "幅度")
                {
                    name = QString("mag(%1)").arg(dataProperty.name);
                }
                else if (dataProperty.dependentVariableType == "相位")
                {
                    name = QString("arg(%1)").arg(dataProperty.name);
                }
                else if (dataProperty.dependentVariableType == "实部")
                {
                    name = QString("Re(%1)").arg(dataProperty.name);
                }
                else if (dataProperty.dependentVariableType == "虚部")
                {
                    name = QString("Im(%1)").arg(dataProperty.name);
                }
            }
            QString unit = dataProperty.unit;
            if (unit.isEmpty() || unit == "空白")
            {
                unit = "none";
            }
            name += "||" + unit;
            if (dataProperty.type == Key)
            {
                name += "||key";
            }
            else if (dataProperty.type == Value)
            {
                name += "||value";
            }
            datas.append(std::make_tuple(name, dataProperty, std::move(vectorTmp)));
        }

        QVector<QPair<QPointF, int>> resultFileData;
        QPointF dataX = {ui->lineEdit_XBegin->text().toDouble(), ui->lineEdit_XEnd->text().toDouble()};
        resultFileData.append(qMakePair<QPointF, int>(dataX, ui->lineEdit_XSamplingNumber->text().toInt()));

        QPointF dataY = {ui->lineEdit_YBegin->text().toDouble(), ui->lineEdit_YEnd->text().toDouble()};
        resultFileData.append(qMakePair<QPointF, int>(dataY, ui->lineEdit_YSamplingNumber->text().toInt()));

        QPointF dataZ = {ui->lineEdit_ZBegin->text().toDouble(), ui->lineEdit_ZEnd->text().toDouble()};
        resultFileData.append(qMakePair<QPointF, int>(dataZ, ui->lineEdit_ZSamplingNumber->text().toInt()));

        QPointF dataTheta = {ui->lineEdit_ThetaBegin->text().toDouble(), ui->lineEdit_ThetaEnd->text().toDouble()};
        resultFileData.append(qMakePair<QPointF, int>(dataTheta, ui->lineEdit_ThetaSamplingNumber->text().toInt()));

        QPointF dataPhi = {ui->lineEdit_PhiBegin->text().toDouble(), ui->lineEdit_PhiEnd->text().toDouble()};
        resultFileData.append(qMakePair<QPointF, int>(dataPhi, ui->lineEdit_PhiSamplingNumber->text().toInt()));

        FileDataTypes fileDataType = FileDataType::None;
        if (ui->checkBox_2DGraph->isChecked())
        {
            fileDataType |= FileDataType::File2DCurve;
        }
        if (ui->checkBox_PolarGraph->isChecked())
        {
            fileDataType |= FileDataType::FilePolar;
        }
        if (ui->checkBox_TwoDHeatMap->isChecked())
        {
            fileDataType |= FileDataType::FileTwoDHeatMap;
        }
        if (ui->checkBox_3DSurfacePlot->isChecked())
        {
            fileDataType |= FileDataType::FileThreeDSurfacePlot;
            if (
                ui->lineEdit_ThetaBegin->text().isEmpty() ||
                ui->lineEdit_ThetaEnd->text().isEmpty() ||
                ui->lineEdit_PhiBegin->text().isEmpty() ||
                ui->lineEdit_PhiEnd->text().isEmpty() ||
                ui->lineEdit_ThetaSamplingNumber->text().isEmpty()||
                ui->lineEdit_PhiSamplingNumber->text().isEmpty()
                )
            {
                IBaseSignalInstance->signal_sendErrorMessageToUI(QStringLiteral("三维曲面图信息不完善"));
                return;
            }
        }
        if (ui->checkBox_3DCloudMap->isChecked())
        {
            fileDataType |= FileDataType::FileThreeDCloudMap;
            if (
                ui->lineEdit_XBegin->text().isEmpty() ||
                ui->lineEdit_XEnd->text().isEmpty() ||
                ui->lineEdit_YBegin->text().isEmpty() ||
                ui->lineEdit_YEnd->text().isEmpty() ||
                ui->lineEdit_ZBegin->text().isEmpty() ||
                ui->lineEdit_ZEnd->text().isEmpty() ||
                ui->lineEdit_XSamplingNumber->text().isEmpty() ||
                ui->lineEdit_YSamplingNumber->text().isEmpty() ||
                ui->lineEdit_ZSamplingNumber->text().isEmpty()
                )
                
            {
                IBaseSignalInstance->signal_sendErrorMessageToUI(QStringLiteral("三维云图信息不完善"));
                return;
            }
        }
        if (ui->checkBox_Table->isChecked())
        {
            fileDataType |= FileDataType::FileDataTable;
        }
        DataImportConfigurationDataInstance->addTextImportData(m_filePath, datas, resultFileData, fileDataType);
        MainWindowSignalHandlerInstance->TextImportDataProcessing(-1, m_filePath, datas, resultFileData, fileDataType);

        auto _customStr = DataImportConfigurationDataInstance->TextAndCsvCustomDataConversionToQString(m_filePath, datas, resultFileData, fileDataType);
        QStringList _pyCodes;
        _pyCodes.append(QString("PostProcessing.dataImport('%1',%2,'%3')").arg(m_filePath).arg(true).arg(_customStr)); // 文件路径，是否是txt和csv，txt和csv的数据
        emit IBaseSignalInstance->signal_execPYCode(_pyCodes, true, false);

        IBaseSignalInstance->signal_UpdateStatusBarInformation(QString("导入数据成功！"), false);
        IdaDialogFrame::accept();
        if (GlobalHelperInstance->getIsNeedPopupWindow())
            auto _res = IdaDialogMsg::showDialog(nullptr, QStringLiteral("导入数据成功！"), EDialogMsg::Normal, QStringLiteral("成功"), { QStringLiteral("确定") });
    }
    void DialogDataImportConfiguration::on_pushButton_Reject_clicked()
    {
        IdaDialogFrame::reject();
    }

    void DialogDataImportConfiguration::slot_TableSelectChange()
    {
        auto _currentWidget = ui->tabWidget->currentWidget();
        if (_currentWidget != m_widget_page1)
        {
            return;
        }
        auto selectedIndexes = ui->tableWidget_DataPreviewSelection->selectionModel()->selectedIndexes();
        int selectColumn = -1;
        m_selectColumnSet.clear();
        for (const auto& index : selectedIndexes)
        {
            if (index.column() == selectColumn)
            {
                continue;
            }
            else
            {
                selectColumn = index.column();
                m_selectColumnSet.insert(selectColumn);
            }
        }
        if (m_selectColumnSet.empty())
        {
            ProhibitAttributeSettings();
        }
        else if (m_selectColumnSet.size() == 1)
        {
            ui->radioButton_DependentVariableSetting->setEnabled(true);
            int index = *m_selectColumnSet.begin();
            const auto& dataProperty = m_dataProperty.at(index);
            ui->radioButton_NoStats->setEnabled(true);
            ui->groupBox_Variable->setEnabled(false);
            ui->groupBox_DependentVariable->setEnabled(false);
            ui->radioButton_VariableSetting->setEnabled(true);
            ui->lineEdit_DependentVariableName->setEnabled(true);
            ui->lineEdit_VariableName->setText(dataProperty.name);
            ui->lineEdit_DependentVariableName->setText(dataProperty.name);
            if (dataProperty.type == None)
            {
                RestoreDefaultKeyShow();
                RestoreDefaultValueShow();
                ui->radioButton_NoStats->setChecked(true);
                ChangeKeyState(false);
                ChangeValueState(false);
            }
            else if (dataProperty.type == Key)
            {
                GetKeyProperty(dataProperty);
                RestoreDefaultValueShow();
                ChangeKeyState(true);
                ChangeValueState(false);
            }
            else if (dataProperty.type == Value)
            {
                GetValueProperty(dataProperty);
                RestoreDefaultKeyShow();
                ChangeKeyState(false);
                ChangeValueState(true);
                if (!dataProperty.isAssociation && dataProperty.associationColumn != -1)
                {
                    ui->groupBox_DependentVariable->setEnabled(false);
                    ui->radioButton_NoStats->setEnabled(false);
                    ui->radioButton_VariableSetting->setEnabled(false);
                }
            }
        }
        else
        {
            ui->radioButton_DependentVariableSetting->setEnabled(true);
            ui->radioButton_NoStats->setEnabled(true);
            ui->groupBox_Variable->setEnabled(false);
            ui->groupBox_DependentVariable->setEnabled(false);
            ui->radioButton_VariableSetting->setEnabled(false);
            ui->lineEdit_DependentVariableName->setEnabled(false);
            ui->lineEdit_DependentVariableName->setText(QString());
            RestoreDefaultKeyShow();
            RestoreDefaultValueShow();
            ChangeKeyState(false);
            ChangeValueState(false);
        }
    }

    void DialogDataImportConfiguration::reject()
    {

        IdaDialogFrame::reject();
    }

    void DialogDataImportConfiguration::accept()
    {

        IdaDialogFrame::accept();
    }

    void DialogDataImportConfiguration::initConnects()
    {
        connect(ui->lineEdit_Other, &QLineEdit::returnPressed, [this]()
            {
                m_splitReg = QRegularExpression(ui->lineEdit_Other->text());
                ParserData(); });
        connect(ui->tableWidget_DataPreviewSelection->selectionModel(), &QItemSelectionModel::selectionChanged, this, &DialogDataImportConfiguration::slot_TableSelectChange);
    }

    void DialogDataImportConfiguration::ParserData()
    {
        int start = ui->spinBox_DataStartRow->value();
        int end = m_text.size();
        if (ui->checkBox_ReadLines->checkState())
        {
            end = start + ui->spinBox_ReadLines->value() - 1 < end ? start + ui->spinBox_ReadLines->value() - 1 : end;
        }
        int column = 1;
        int errorRow = 0;
        QStringList headerTextList;
        m_data.clear();
        for (int i = start - 1; i < end; ++i)
        {
            QStringList tmp = m_text.at(i).split(m_splitReg, QString::SkipEmptyParts);
            if (i == start - 1)
            {
                column = tmp.size();
                if (ui->checkBox_IncludeTitle->checkState())
                {
                    tmp.first().remove(QRegularExpression("#+"));
                    headerTextList = std::move(tmp);
                    continue;
                }
            }
            QVector<QPair<bool, QString>> rowData = QVector<QPair<bool, QString>>(column, qMakePair(false, QString()));
            for (int j = 0; j < tmp.size(); ++j)
            {
                QString s;
                if (j < column - 1)
                {
                    s = tmp.at(j);
                }
                else if (j == column - 1)
                {
                    s = tmp.mid(j).join(m_splitReg.pattern().remove("+"));
                }
                else
                {
                    break;
                }
                auto reg = QRegularExpression("^[ \t]*(-?[0-9]+(\\.[0-9]+)?([Ee][\\+-][0-9]+)?)[ \t]*$");
                auto match = reg.match(s);
                if (match.hasMatch())
                {
                    rowData[j].first = true;
                    rowData[j].second = match.captured(1);
                }
                else
                {
                    rowData[j].second = s;
                }
            }
            if (errorRow == 0)
            {
                for (const auto& columnData : rowData)
                {
                    if (!columnData.first)
                    {
                        errorRow = i + 1;
                    }
                }
            }
            m_data.append(std::move(rowData));
        }
        ui->tableWidget_DataPreviewSelection->setColumnCount(column);
        m_dataProperty = QVector<DataProperty>(column, DataProperty());
        if (!headerTextList.isEmpty())
        {
            m_headerTextList.clear();
            ++start;
            for (const auto& heardName : headerTextList)
            {
                QString heardText;
                auto splitTmp = heardName.split("||", QString::SkipEmptyParts);
                if (splitTmp.size() == 3)
                {
                    heardText = splitTmp.first();
                }
                else
                {
                    heardText = heardName;
                }
                m_headerTextList.append(heardText);
            }
        }
        else
        {
            QStringList defaltHeaderText;
            for (int i = 0; i < column; ++i)
            {
                defaltHeaderText.append(QString::number(i + 1));
            }
            m_headerTextList = defaltHeaderText;
        }
        ui->tableWidget_DataPreviewSelection->setHorizontalHeaderLabels(m_headerTextList);
        for (int i = 0; i < column; ++i)
        {
            m_dataProperty[i].name = m_headerTextList.at(i);
            m_dataProperty[i].index = i;
        }
        int tableStart = 1;
        int errorIndex = errorRow - start + 1;
        int tableEnd = tableStart + 19 < m_data.size() ? tableStart + 19 : m_data.size();
        if (errorIndex > 10)
        {
            tableEnd = errorIndex + 10 < m_data.size() ? errorIndex + 10 : m_data.size();
            tableStart = tableEnd - 19;
        }
        QStringList columnIndexList;
        ui->tableWidget_DataPreviewSelection->setRowCount(tableEnd - tableStart + 1);
        for (int i = 0; i < tableEnd - tableStart + 1; ++i)
        {
            columnIndexList.append(QString::number(i + tableStart + start - 1));
            for (int j = 0; j < column; ++j)
            {
                auto item = new QTableWidgetItem(m_data.at(i + tableStart - 1).at(j).second);
                if (!m_data.at(i + tableStart - 1).at(j).first)
                {
                    item->setBackgroundColor(Qt::red);
                }
                ui->tableWidget_DataPreviewSelection->setItem(i, j, item);
            }
        }
        ui->tableWidget_DataPreviewSelection->setVerticalHeaderLabels(columnIndexList);
    }

    void DialogDataImportConfiguration::ProhibitAttributeSettings()
    {
        ui->radioButton_NoStats->setAutoExclusive(false);
        ui->radioButton_NoStats->setChecked(false);
        ui->radioButton_NoStats->setAutoExclusive(true);
        ui->radioButton_NoStats->setEnabled(false);
        ui->radioButton_VariableSetting->setAutoExclusive(false);
        ui->radioButton_VariableSetting->setChecked(false);
        ui->radioButton_VariableSetting->setAutoExclusive(true);
        ui->radioButton_VariableSetting->setEnabled(false);
        ui->radioButton_DependentVariableSetting->setAutoExclusive(false);
        ui->radioButton_DependentVariableSetting->setChecked(false);
        ui->radioButton_DependentVariableSetting->setAutoExclusive(true);
        ui->radioButton_DependentVariableSetting->setEnabled(false);
    }

    void DialogDataImportConfiguration::ChangeKeyState(bool keyState)
    {
        // ui->radioButton_VariableSetting->setAutoExclusive(false);
        ui->radioButton_VariableSetting->setChecked(keyState);
        // ui->radioButton_VariableSetting->setAutoExclusive(true);
        ui->groupBox_Variable->setEnabled(keyState);
    }

    void DialogDataImportConfiguration::ChangeValueState(bool valueState)
    {
        // ui->radioButton_DependentVariableSetting->setAutoExclusive(false);
        ui->radioButton_DependentVariableSetting->setChecked(valueState);
        // ui->radioButton_DependentVariableSetting->setAutoExclusive(true);
        ui->groupBox_DependentVariable->setEnabled(valueState);
    }

    void DialogDataImportConfiguration::RestoreDefaultKeyShow()
    {
        ui->comboBox_VariableCategory->setCurrentIndex(0);
        ui->comboBox_VariableCategoryUnit->setCurrentIndex(0);
    }

    void DialogDataImportConfiguration::RestoreDefaultValueShow()
    {
        ui->comboBox_DependentVariable->setCurrentIndex(0);
        ui->label_DependentVariable1->clear();
        ui->comboBox_DependentVariableCategory->setCurrentIndex(0);
        ui->comboBox_DependentVariableCategoryUnit->setCurrentIndex(0);
        ui->checkBox_Relevance->setChecked(false);
        ui->lineEdit_Relevance->setText(QString::number(m_selectColumnSet.size()));
        ui->checkBox_dB->setChecked(false);
    }

    void DialogDataImportConfiguration::RestoreNoneProperty(DataProperty& noneProperty)
    {
        RestoreAssociationValueProperty(noneProperty);
        noneProperty.type = None;
        noneProperty.name = m_headerTextList.at(noneProperty.index);
        noneProperty.dependentVariable.clear();
        noneProperty.dependentVariableType.clear();
        noneProperty.category.clear();
        noneProperty.unit.clear();
        noneProperty.isAssociation = false;
        noneProperty.skipColumns = 1;
        noneProperty.isDB = false;
        noneProperty.associationColumn = -1;
        UpdateDataShow();
    }

    void DialogDataImportConfiguration::GetKeyProperty(const DataProperty& keyProperty)
    {
        ui->lineEdit_VariableName->setText(keyProperty.name);
        ui->comboBox_VariableCategory->setCurrentText(keyProperty.category);
        ui->comboBox_VariableCategoryUnit->setCurrentText(keyProperty.unit);
    }

    void DialogDataImportConfiguration::SetKeyProperty(DataProperty& keyProperty)
    {
        if (!ui->groupBox_Variable->isEnabled())
        {
            return;
        }
        RestoreAssociationValueProperty(keyProperty);
        keyProperty.type = Key;
        keyProperty.name = ui->lineEdit_VariableName->text();
        keyProperty.category = ui->comboBox_VariableCategory->currentText();
        keyProperty.unit = ui->comboBox_VariableCategoryUnit->currentText();
        UpdateDataShow();
    }

    void DialogDataImportConfiguration::GetValueProperty(const DataProperty& valueProperty)
    {
        ui->lineEdit_DependentVariableName->setText(valueProperty.name);
        ui->comboBox_DependentVariable->setCurrentText(valueProperty.dependentVariable);
        ui->label_DependentVariable1->setText(valueProperty.dependentVariableType);
        ui->comboBox_DependentVariableCategory->setCurrentText(valueProperty.category);
        ui->comboBox_DependentVariableCategoryUnit->setCurrentText(valueProperty.unit);
        ui->checkBox_Relevance->setChecked(valueProperty.isAssociation);
        ui->lineEdit_Relevance->setText(QString::number(valueProperty.skipColumns));
        ui->checkBox_dB->setChecked(valueProperty.isDB);
    }

    void DialogDataImportConfiguration::SetValueProperty(DataProperty& valueProperty, bool shouldChanegName)
    {
        if (!ui->groupBox_DependentVariable->isEnabled())
        {
            return;
        }
        valueProperty.type = Value;
        /*if (!ui->lineEdit_DependentVariableName->text().isEmpty())
        {*/
        if (shouldChanegName)
        {
            valueProperty.name = ui->lineEdit_DependentVariableName->text();
        }
        //}
        valueProperty.dependentVariable = ui->comboBox_DependentVariable->currentText();
        valueProperty.dependentVariableType = ui->label_DependentVariable1->text();
        valueProperty.category = ui->comboBox_DependentVariableCategory->currentText();
        valueProperty.unit = ui->comboBox_DependentVariableCategoryUnit->currentText();
        if (valueProperty.isAssociation && !ui->checkBox_Relevance->isChecked())
        {
            RestoreAssociationValueProperty(valueProperty);
        }
        else if (ui->checkBox_Relevance->isChecked() && valueProperty.skipColumns != ui->lineEdit_Relevance->text().toInt())
        {
            RestoreAssociationValueProperty(valueProperty);
        }
        valueProperty.isAssociation = ui->checkBox_Relevance->isChecked();
        valueProperty.skipColumns = ui->lineEdit_Relevance->text().toInt();
        valueProperty.isDB = ui->checkBox_dB->isChecked();
        SetAssociationValueProperty(valueProperty);
        UpdateDataShow();
    }

    void DialogDataImportConfiguration::RestoreAssociationValueProperty(const DataProperty& valueProperty)
    {
        if (valueProperty.type == Value && valueProperty.isAssociation && valueProperty.associationColumn > -1)
        {
            if (valueProperty.associationColumn > m_dataProperty.size() - 1)
            {
                return;
            }
            DataProperty& associationValue = m_dataProperty[valueProperty.associationColumn];
            if (associationValue.type != Value)
            {
                return;
            }
            if (!associationValue.isAssociation && associationValue.associationColumn == valueProperty.index)
            {
                RestoreNoneProperty(associationValue);
            }
        }
    }

    void DialogDataImportConfiguration::SetAssociationValueProperty(DataProperty& valueProperty)
    {
        if (valueProperty.isAssociation)
        {
            int associationIndex = valueProperty.index + valueProperty.skipColumns;
            if (associationIndex > m_dataProperty.size() - 1)
            {
                IBaseSignalInstance->signal_sendErrorMessageToUI("关联列数超过总数据列数！！！");
                RestoreNoneProperty(valueProperty);
                ui->radioButton_NoStats->setEnabled(true);
                ui->groupBox_Variable->setEnabled(false);
                ui->groupBox_DependentVariable->setEnabled(false);
                RestoreDefaultValueShow();
                ui->radioButton_NoStats->setChecked(true);
                return;
            }
            valueProperty.associationColumn = associationIndex;
            DataProperty& associationValue = m_dataProperty[associationIndex];
            if (associationValue.type == Key || (associationValue.type == Value && associationValue.associationColumn != valueProperty.index))
            {
                IBaseSignalInstance->signal_sendErrorMessageToUI("关联列数据已设置属性，请确认后重新设置。");
                RestoreNoneProperty(valueProperty);
                ui->radioButton_NoStats->setEnabled(true);
                ui->groupBox_Variable->setEnabled(false);
                ui->groupBox_DependentVariable->setEnabled(false);
                RestoreDefaultValueShow();
                ui->radioButton_NoStats->setChecked(true);
                return;
            }
            associationValue.type = valueProperty.type;
            associationValue.name = valueProperty.name;
            associationValue.dependentVariable = valueProperty.dependentVariable;
            associationValue.dependentVariableType = associationValue.dependentVariable.mid(associationValue.dependentVariable.size() - 3, 2);
            associationValue.category = valueProperty.category;
            associationValue.unit = valueProperty.unit;
            associationValue.isAssociation = false;
            associationValue.skipColumns = 1;
            associationValue.isDB = valueProperty.isDB;
            associationValue.associationColumn = valueProperty.index;
        }
        else
        {
            valueProperty.associationColumn = -1;
        }
    }

    void DialogDataImportConfiguration::UpdateDataShow()
    {
        for (int i = 0; i < m_dataProperty.size(); ++i)
        {
            const auto& property = m_dataProperty.at(i);
            ui->tableWidget_DataPreviewSelection->horizontalHeaderItem(i)->setText(property.name);
            QColor color;
            if (property.type == None)
            {
                color = Qt::white;
            }
            else if (property.type == Key)
            {
                color = Qt::blue;
            }
            else if (property.type == Value)
            {
                color = Qt::yellow;
            }
            for (int row = 0; row < ui->tableWidget_DataPreviewSelection->rowCount(); ++row)
            {
                QTableWidgetItem* item = ui->tableWidget_DataPreviewSelection->item(row, i);
                if (item == nullptr)
                {
                    continue;
                }
                item->setBackground(color);
            }
        }
    }

    void DialogDataImportConfiguration::GetStartLine()
    {
        int startNumber = 0;
        for (int i = 0; i < m_text.size(); ++i)
        {
            const QString& text = m_text.at(i);
            if (text.isEmpty())
            {
                continue;
            }
            if (text.at(0).isNumber())
            {
                startNumber = i;
                break;
            }
        }
        if (ui->checkBox_IncludeTitle->checkState() && startNumber > 0)
        {
            --startNumber;
        }
        ui->spinBox_DataStartRow->blockSignals(true);
        ui->spinBox_DataStartRow->setValue(startNumber + 1);
        ui->spinBox_DataStartRow->blockSignals(false);
    }

} // namespace pst
